package search.config;


import org.elasticsearch.search.sort.SortOrder;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by julianzliu on 2016/7/3.
 */
public class SearchParameters {
    /**
     * Created by julianzliu on 2016/7/1.
     */
    public static class MinimumMatch {

        public static String default_minimum = "-1";
        public static String ori_minimum = "-1"; // 原始查询匹配的词语数
        public static String exp_minimum = "100%"; // 扩展后的查询匹配的词语数（可以用扩展的词语代替原始词语进行匹配）
    }

    public static class Boosting {
        /*
        *
         */
        // 原始查询，使用 ik_smart
        public static float original_base_query = 2.0f;
        // 单独使用 ik_smart_syon扩展的查询
        public static float original_syno_query = 1.0f;

        // 原始查询，无扩展项
        public static float original_query = 1.0f;
        // 扩展查询有4个扩展项，要稀释他们的影响，boost为 1/4
        public static float expasion_query = 0.25f;




        /*
        *
         */
        public static float subquery = 3.0f;
        public static float multi = 4.0f;
        public static float whole = 1.0f;
        public static float parts = 2.0f;
        /*
        *
         */
        public static float allfield = 1.0f;
        public static float fulltext = 2.0f;
        public static float pinyin = 1.0f;
        public static float source = 1.0f;
        public static float subject = 3.0f;
        public static float title = 5.0f;

    }





    /**
     * Created by julianzliu on 2016/7/3.
     */
    public static class MediaTypes {
        public static String video_type = "video";
        public static String audio_type = "audio";
        public static String picture_type = "picture";

        public static String getMeidiaType(String mediatype){
            String[] mediatypes = {video_type, audio_type, picture_type};
            for(String type : mediatypes){
                if(mediatype.equalsIgnoreCase(type)){
                    return type;
                }
            }
            return video_type;
        }
    }



    public static class SortTypes {
        public static String relevancy = "relevancy";
        public static String earliest = "earliest";
        public static String latest = "latest";

        public static Map<String,String> sort_fields = new HashMap<>();
        public static Map<String,SortOrder> sort_orders = new HashMap<>();

        static {
            sort_fields.put(relevancy, "_score");
            sort_orders.put(relevancy, SortOrder.DESC);

            sort_fields.put(earliest  , "UploadTime");
            sort_orders.put(earliest  , SortOrder.ASC);

            sort_fields.put(latest    , "UploadTime");
            sort_orders.put(latest    , SortOrder.DESC);

        }


        public static String getSortType(String sorttype){
            String[] sorttypes = {relevancy, earliest, latest};
            for(String sort : sorttypes){
                if(sorttype.equalsIgnoreCase(sort)) return sort;
            }
            return relevancy;
        }
    }
}
